package com.zzl.bonds.ticket.controller;

import com.zzl.apidoc.annotation.ApidocController;
import com.zzl.apidoc.annotation.ApidocOperation;
import com.zzl.apidoc.annotation.ApidocParam;
import com.zzl.bonds.ticket.dto.TickefinanceDataAddDto;
import com.zzl.bonds.ticket.dto.TickefinanceDataUpdateDto;
import com.zzl.bonds.ticket.entity.TicketFinanceDataEntity;
import com.zzl.bonds.ticket.service.TicketFinanceDataService;
import com.zzl.general.common.apidoc.annotation.ApidocParamsPage;
import com.zzl.general.common.apidoc.annotation.ApidocResultKeyValR;
import com.zzl.general.common.apidoc.annotation.ApidocReturnPage;
import com.zzl.general.common.apidoc.annotation.ApidocReturnR;
import com.zzl.general.common.apidoc.constants.ResultTypeInR;
import com.zzl.general.common.ctrl.WebBaseCtrl;
import com.zzl.general.common.exception.SysException;
import com.zzl.general.common.utils.LogUtils;
import com.zzl.general.common.utils.PageUtils;
import com.zzl.general.common.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * 融资资料表
 *
 * @author gull
 * @date 2022-07-06 13:43:52
 */
@ApidocController("融资资料表")
@RestController
@SuppressWarnings("javadoc")
@RequestMapping("ticket/tickefinancedata")
@Slf4j
public class TicketFinanceDataController extends WebBaseCtrl {
    @SuppressWarnings("all")
    @Autowired
    private TicketFinanceDataService ticketFinanceDataService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApidocOperation(description = "分页查询融资资料表数据", operationId = "ticket/tickefinancedata" + "/list")
    @ApidocReturnPage(genericTypeClass = TicketFinanceDataEntity.class)
    public Result list(@ApidocParamsPage(name = "params") @RequestParam Map<String, Object> params) {
        PageUtils page = ticketFinanceDataService.queryPage(params);
        return Result.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    @ApidocOperation(description = "通过id获取融资资料表数据", operationId = "ticket/tickefinancedata" + "/info/{id}")
    @ApidocReturnR(otherkv = {
            @ApidocResultKeyValR(resultType = ResultTypeInR.TYPE_OBJECT, key = "tickefinanceData", valueClass = TicketFinanceDataEntity.class)
    })
    public Result info(@ApidocParam(description = "融资资料表id", name = "id", required = true) @PathVariable("id") String id) {
        TicketFinanceDataEntity tickefinanceData = ticketFinanceDataService.getById(id);
        return Result.ok().put("data", tickefinanceData);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApidocOperation(description = "保存融资资料表", operationId = "ticket/tickefinancedata" + "/save")
    @ApidocReturnR
    public Result save(@ApidocParam(description = "保存的融资资料表对象值", name = "{tickefinanceData}", required = true) @RequestBody TickefinanceDataAddDto tickefinanceData) {
        try {
            ticketFinanceDataService.saveTickefinanceData(tickefinanceData, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    @ApidocOperation(description = "修改融资资料表", operationId = "ticket/tickefinancedata" + "/update")
    @ApidocReturnR
    public Result update(@ApidocParam(description = "修改的融资资料表对象值", name = "tickefinanceData", required = true) @RequestBody TickefinanceDataUpdateDto tickefinanceData) {
        try {
            ticketFinanceDataService.updateTickefinanceDataById(tickefinanceData, this.getUser());
            return Result.ok();
        } catch (SysException e) {
            LogUtils.logSysException(log, e);
            return Result.error(e.getMsg());
        }
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @ApidocOperation(description = "删除融资资料表", operationId = "ticket/tickefinancedata" + "/delete")
    @ApidocReturnR
    public Result delete(@ApidocParam(description = "删除的融资资料表对象id集合", name = "ids", required = true) @RequestBody String[] ids) {
        ticketFinanceDataService.removeByIds(Arrays.asList(ids));
        return Result.ok();
    }

}
